package top.houry.im.ui.controller;


import javafx.scene.control.Alert;
import top.houry.im.ui.init.ImUiLoginInit;
import top.houry.im.ui.interfaces.ImUiLoginEvent;
import top.houry.im.ui.interfaces.ImUiLoginMethod;

public class ImUiLoginController extends ImUiLoginInit implements ImUiLoginMethod {

    public ImUiLoginController(ImUiLoginEvent loginEvent) {
        super(loginEvent);
        this.move();
        initMinEvent();
        initCloseEvent();
        initNetworkTip();
        initLoginButtonEvent();

    }

    @Override
    public void loginFail() {
//        Alert alert = new Alert(Alert.AlertType.ERROR);

    }

    @Override
    public void loginSuccess() {
        this.close();
        // 打开聊天窗口
//        chat.doShow();
    }

    @Override
    public void showNetworkTip(Boolean flag) {
        this.networkTip.setVisible(flag);
    }

    private void initMinEvent() {
        this.loginMin.setOnAction(event -> this.setIconified(true));
    }

    private void initCloseEvent() {
        this.loginClose.setOnAction(event -> {
            this.close();
            System.exit(0);
        });
    }

    private void initLoginButtonEvent() {
        this.loginButton.setOnAction(event -> loginEvent.login(this.userId.getText(), this.userPassword.getText()));
    }

    private void initNetworkTip() {
        this.showNetworkTip(false);
    }
}
